package com.cn.crmsystem.service.businessService.Impl;

import com.cn.crmsystem.mapper.businessMapper.OrderMapper;
import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.Order;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.service.businessService.OrderService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {
    private OrderMapper orderMapper;
    /**
     * 查询所有订单
     *
     * @return
     */
    @Override
    public ResultJson selectOrderAll(Map map) {
        List selectOrderAll = orderMapper.selectOrderAll(map);
        ResultJson resultJson = new ResultJson();
        if (selectOrderAll != null) {
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }

    @Override
    public ResultJson selectOrderById(Integer id) {
        Order selectOrderById = orderMapper.seleOrderById(id);
        ResultJson resultJson = new ResultJson();
        if (selectOrderById != null) {
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }

    @Override
    public ResultJson addOrder(Order order,Login login) {
        HashMap<Object,Object> map = new HashMap<>();
        map.put("order",order);
        map.put("login",login);
        int addOrrder = orderMapper.addOrder(map);
        ResultJson resultJson = new ResultJson();
        if (addOrrder >0) {
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return  resultJson;
    }

    @Override
    public ResultJson updateOrder(Order order) {
        int updateOrder = orderMapper.updateOrder(order);
        ResultJson resultJson = new ResultJson();
        if (updateOrder >0) {
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return  resultJson;
    }

    @Override
    public ResultJson deleteByIdOrder(Integer id) {
        int deleteByIdOrder = orderMapper.deleteByIdOrder(id);
        ResultJson resultJson = new ResultJson();
        if (deleteByIdOrder>0){
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }
}
